/****************************************************************************
*                                                                           *
* Copyright (c) Ionescu M. Marius. All rights reserved(2010).               *
*                                                                           *
****************************************************************************/

using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Security;

public partial class LoginPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Tools.userHipoSession = null;

        if ((Request.QueryString["name"] != null && Request.QueryString["name"] != ""))
        {
			this.Trace.Write("Info", string.Format("name '{0}' found in QS; user id from Session is '{1}'", Request.QueryString["name"], Session["UserID"]));
            FormsAuthentication.SignOut();
            Session["UserID"] = null;

            string strUserID = Tools.GetUserID(Request.QueryString["name"].ToString(), null);
			this.Trace.Write("Info", "user id from db = " + strUserID);

            if (strUserID != "")
            {
                FormsAuthentication.SetAuthCookie(Tools.userHipo, true);
                Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName + "_UserID", strUserID));
                Response.Cookies[FormsAuthentication.FormsCookieName + "_UserID"].Expires = Response.Cookies[FormsAuthentication.FormsCookieName].Expires;

                Response.Redirect("Default.aspx");
            }
            else
            {
                FormsAuthentication.SignOut();
            }
        }
    }

    protected void Login1_LoggedIn_(object sender, EventArgs e)
    {
        //Response.Redirect("Default.aspx");
    }
}
